COMPILE_FOR_DS = 1 -- 0: no, 1: yes
-- ##### CONST  ######

MICROLUA_VERSION = "3.0"
NANOLUA_VERSION = "2.5"
LUA_TYPE = "nano"
LUA_DIR = "25"

LUA_FULLDIR = LUA_TYPE.."/"..LUA_DIR

str = ""
if COMPILE_FOR_DS == 1 then
   str = "/lua/"..LUA_FULLDIR.."/libs/"
end

-- Load libs --
a = package.path
package.path = ";fat:/lua/"..LUA_FULLDIR.."/libs/?.lua;fat:/lua/"..LUA_FULLDIR.."/libs/micro/?.lua;fat:/lua/"..LUA_FULLDIR.."/libs/nano/?.lua"
-- Prioritary libs --
require ("vars")
require ("screen")
-- Micro Lua Libs --
require ("controls")
require ("timer")
require ("debug")
require ("system")
require ("datetime")
require ("sprite")
require ("ini")
-- Nano Lua Libs --
require ("collisions") -- By Quent42340
require ("color") -- By Quent42340
require ("dsuser") -- By Quent42340
require ("formes") -- By Stef14
require ("sb") -- By Killer01
require ("vars2") -- By Quent42340
-- Close load libs --
package.path = a
a = nil
-- END --

-- ################################ START ################################

screen.init()
os.initTimer()

NB_FPS = 30
NB_FPS_COUNTER = 0
tmrFpsCounter = Timer.new()
tmrFpsCounter:start()

startDrawing()

while true do

   status_global_microlua_errors, err_global_microlua_errors = pcall(function ()
      str = ""
      if COMPILE_FOR_DS == 1 then
         str = "/lua/"..LUA_FULLDIR.."/libs/"
      end   
      dofile(str.."shell.lua")
   end)
   if err_global_microlua_errors ~= nil then
      Debug.OFF()   
      Controls.read()
      while not Keys.newPress.Start do
         Controls.read()
         screen.drawFillRect(SCREEN_UP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Color.new(0, 0, 31))
         screen.drawFillRect(SCREEN_DOWN, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Color.new(0, 0, 31))
         screen.drawTextBox(SCREEN_DOWN, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, "*** ERRORS OCCURED ***\n"..err_global_microlua_errors.."\n"..debug.traceback().."\n*********************\n\nPress START to continue")
         render()
      end
   end

end
